#!/usr/bin/env python
'''
Plots \ln(M_L) vs \ln(L) for set of temperatures
'''

import sys
sys.path += ['..']
import common
import os
import math
import matplotlib.pyplot
import numpy

# tList = [0.60, 0.62, 0.63, 0.64, 0.65, 0.70, 0.80, 0.90, 0.92, 0.95, 0.96, 1.00, 1.05]
tList = [0.60, 0.62, 0.65, 0.70, 0.80, 0.90, 0.92, 0.95, 0.96, 1.00, 1.05]
path = os.path.join('..', '..', '..', '..', 'results', 'square_clock', 'J_1.0', 'q_6')

lList = common.choice(path)

# l1List = [ math.log(eval(tl.replace('L_',''))) for tl in lList ]

for tT in tList:
	mList = []
	lList1 = []
	for tL in lList:		
		L = int( tL.replace('L_', '') )
		lPath = os.path.join(path, tL, 'M')
		Temperature, M, err  = common.sorted_list(lPath)
		try:
			tIndex = Temperature.index(tT)
		except:
			pass
		else:
			mList += [ math.log( M[tIndex] ) ]
			lList1 += [ math.log(L) ]

	A = numpy.vstack([lList1, numpy.ones(len(lList1))]).T

	temp = numpy.linalg.lstsq(A, mList)
	
	m, c = temp[0]  
	print
	print 'Temperature',tT
	print 'm',m
	print 'c',c
	print 'error', temp[1]
		

	
	matplotlib.pyplot.plot( lList1, mList,'*-', label = r'$T = %.2f$'%(tT))
matplotlib.pyplot.legend(loc = 'lower left', shadow = True)
matplotlib.pyplot.xlabel(r'$\ln(L)$')
matplotlib.pyplot.ylabel(r'$\ln(m_L)$')
matplotlib.pyplot.show()